github.com/safing/portbase@v0.19.5/updater/storage_test.go (about) 1 package updater 2 3 /* 4 func testLoadLatestScope(t *testing.T, basePath, filePath, expectedIdentifier, expectedVersion string) { 5 fullPath := filepath.Join(basePath, filePath) 6 7 // create dir 8 dirPath := filepath.Dir(fullPath) 9 err := os.MkdirAll(dirPath, 0755) 10 if err != nil { 11 t.Fatalf("could not create test dir: %s\n", err) 12 return 13 } 14 15 // touch file 16 err = os.WriteFile(fullPath, []byte{}, 0644) 17 if err != nil { 18 t.Fatalf("could not create test file: %s\n", err) 19 return 20 } 21 22 // run loadLatestScope 23 latest, err := ScanForLatest(basePath, true) 24 if err != nil { 25 t.Errorf("could not update latest: %s\n", err) 26 return 27 } 28 for key, val := range latest { 29 localUpdates[key] = val 30 } 31 32 // test result 33 version, ok := localUpdates[expectedIdentifier] 34 if !ok { 35 t.Errorf("identifier %s not in map", expectedIdentifier) 36 t.Errorf("current map: %v", localUpdates) 37 } 38 if version != expectedVersion { 39 t.Errorf("unexpected version for %s: %s", filePath, version) 40 } 41 } 42 43 func TestLoadLatestScope(t *testing.T) { 44 45 updatesLock.Lock() 46 defer updatesLock.Unlock() 47 48 tmpDir, err := os.MkdirTemp("", "testing_") 49 if err != nil { 50 t.Fatalf("could not create test dir: %s\n", err) 51 return 52 } 53 defer os.RemoveAll(tmpDir) 54 55 testLoadLatestScope(t, tmpDir, "all/ui/assets_v1-2-3.zip", "all/ui/assets.zip", "1.2.3") 56 testLoadLatestScope(t, tmpDir, "all/ui/assets_v1-2-4b.zip", "all/ui/assets.zip", "1.2.4b") 57 testLoadLatestScope(t, tmpDir, "all/ui/assets_v1-2-5.zip", "all/ui/assets.zip", "1.2.5") 58 testLoadLatestScope(t, tmpDir, "all/ui/assets_v1-3-4.zip", "all/ui/assets.zip", "1.3.4") 59 testLoadLatestScope(t, tmpDir, "all/ui/assets_v2-3-4.zip", "all/ui/assets.zip", "2.3.4") 60 testLoadLatestScope(t, tmpDir, "all/ui/assets_v1-2-3.zip", "all/ui/assets.zip", "2.3.4") 61 testLoadLatestScope(t, tmpDir, "all/ui/assets_v1-2-4.zip", "all/ui/assets.zip", "2.3.4") 62 testLoadLatestScope(t, tmpDir, "all/ui/assets_v1-3-4.zip", "all/ui/assets.zip", "2.3.4") 63 testLoadLatestScope(t, tmpDir, "os_platform/portmaster/portmaster_v1-2-3", "os_platform/portmaster/portmaster", "1.2.3") 64 testLoadLatestScope(t, tmpDir, "os_platform/portmaster/portmaster_v2-1-1", "os_platform/portmaster/portmaster", "2.1.1") 65 testLoadLatestScope(t, tmpDir, "os_platform/portmaster/portmaster_v1-2-3", "os_platform/portmaster/portmaster", "2.1.1") 66 67 } 68 */