mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 10:37:24 -04:00 
			
		
		
		
	* Initial concept for pluggable storage (sans tests and docs) * Add TLS storage docs, test harness, and minor clean up from code review * Fix issue with caddymain's temporary moveStorage * Formatting improvement on struct array literal by removing struct name * Pluggable storage changes: * Change storage interface to persist all site or user data in one call * Add lock/unlock calls for renewal and cert obtaining * Key fields on composite literals
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package storagetest
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"github.com/mholt/caddy/caddytls"
 | |
| 	"os"
 | |
| 	"path/filepath"
 | |
| 	"testing"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| // TestFileStorage tests the file storage set with the test harness in this
 | |
| // package.
 | |
| func TestFileStorage(t *testing.T) {
 | |
| 	emailCounter := 0
 | |
| 	storageTest := &StorageTest{
 | |
| 		Storage:  caddytls.FileStorage("./testdata"),
 | |
| 		PostTest: func() { os.RemoveAll("./testdata") },
 | |
| 		AfterUserEmailStore: func(email string) error {
 | |
| 			// We need to change the dir mod time to show a
 | |
| 			// that certain dirs are newer.
 | |
| 			emailCounter++
 | |
| 			fp := filepath.Join("./testdata", "users", email)
 | |
| 
 | |
| 			// What we will do is subtract 10 days from today and
 | |
| 			// then add counter * seconds to make the later
 | |
| 			// counters newer. We accept that this isn't exactly
 | |
| 			// how the file storage works because it only changes
 | |
| 			// timestamps on *newly seen* users, but it achieves
 | |
| 			// the result that the harness expects.
 | |
| 			chTime := time.Now().AddDate(0, 0, -10).Add(time.Duration(emailCounter) * time.Second)
 | |
| 			if err := os.Chtimes(fp, chTime, chTime); err != nil {
 | |
| 				return fmt.Errorf("Unable to change file time for %v: %v", fp, err)
 | |
| 			}
 | |
| 			return nil
 | |
| 		},
 | |
| 	}
 | |
| 	storageTest.Test(t, false)
 | |
| }
 |