MCPcopy
hub / github.com/helmfile/helmfile / TestRemote_HttpUrlWithQueryParams

Function TestRemote_HttpUrlWithQueryParams

pkg/remote/remote_test.go:1054–1112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1052}
1053
1054func TestRemote_HttpUrlWithQueryParams(t *testing.T) {
1055 cacheDir := CacheDir()
1056 cleanfs := map[string]string{
1057 cacheDir: "",
1058 }
1059 cachefs := map[string]string{
1060 filepath.Join(cacheDir, "https_gitlab_example_com.ref=abc123/api/v4/projects/test/repository/files/values.yaml", "raw"): "cached: content",
1061 }
1062
1063 testcases := []struct {
1064 name string
1065 files map[string]string
1066 expectCacheHit bool
1067 }{
1068 {name: "cache miss", files: cleanfs, expectCacheHit: false},
1069 {name: "cache hit", files: cachefs, expectCacheHit: true},
1070 }
1071
1072 for _, tt := range testcases {
1073 t.Run(tt.name, func(t *testing.T) {
1074 testfs := testhelper.NewTestFs(tt.files)
1075
1076 hit := true
1077
1078 get := func(wd, src, dst string) error {
1079 hit = false
1080 return nil
1081 }
1082
1083 getter := &testGetter{get: get}
1084 remote := &Remote{
1085 Logger: helmexec.NewLogger(io.Discard, "debug"),
1086 Home: cacheDir,
1087 Getter: getter,
1088 S3Getter: getter,
1089 HttpGetter: getter,
1090 fs: testfs.ToFileSystem(),
1091 }
1092
1093 url := "https://gitlab.example.com/api/v4/projects/test/repository/files/values.yaml/raw?ref=abc123"
1094 file, err := remote.Fetch(url)
1095 if err != nil {
1096 t.Fatalf("unexpected error: %v", err)
1097 }
1098
1099 expectedFile := filepath.Join(cacheDir, "https_gitlab_example_com.ref=abc123/api/v4/projects/test/repository/files/values.yaml", "raw")
1100 if file != expectedFile {
1101 t.Errorf("unexpected file located: %s vs expected: %s", file, expectedFile)
1102 }
1103
1104 if tt.expectCacheHit && !hit {
1105 t.Errorf("unexpected cache miss")
1106 }
1107 if !tt.expectCacheHit && hit {
1108 t.Errorf("unexpected cache hit")
1109 }
1110 })
1111 }

Callers

nothing calls this directly

Calls 5

ToFileSystemMethod · 0.95
FetchMethod · 0.95
NewTestFsFunction · 0.92
NewLoggerFunction · 0.92
CacheDirFunction · 0.85

Tested by

no test coverage detected