(t *testing.T)
| 1132 | } |
| 1133 | |
| 1134 | func TestStoreLoadSaveAndQueryBranches(t *testing.T) { |
| 1135 | dir := t.TempDir() |
| 1136 | path := filepath.Join(dir, MetadataFilename) |
| 1137 | store := NewStoreAt(path) |
| 1138 | if store.Path() != path { |
| 1139 | t.Fatalf("Path() = %q", store.Path()) |
| 1140 | } |
| 1141 | empty, err := store.Load() |
| 1142 | if err != nil { |
| 1143 | t.Fatalf("Load missing file returned error: %v", err) |
| 1144 | } |
| 1145 | if empty.Version != CurrentCredentialVersion || empty.GitHTTPURL != "" { |
| 1146 | t.Fatalf("empty file = %#v", empty) |
| 1147 | } |
| 1148 | if err := store.Save(nil); err != nil { |
| 1149 | t.Fatalf("Save(nil) returned error: %v", err) |
| 1150 | } |
| 1151 | file, err := store.Load() |
| 1152 | if err != nil { |
| 1153 | t.Fatalf("Load after Save(nil) returned error: %v", err) |
| 1154 | } |
| 1155 | if file.Version != CurrentCredentialVersion { |
| 1156 | t.Fatalf("Version after Save(nil) = %d", file.Version) |
| 1157 | } |
| 1158 | if err := os.WriteFile(path, []byte{}, 0600); err != nil { |
| 1159 | t.Fatalf("write empty metadata: %v", err) |
| 1160 | } |
| 1161 | empty, err = store.Load() |
| 1162 | if err != nil { |
| 1163 | t.Fatalf("Load empty file returned error: %v", err) |
| 1164 | } |
| 1165 | if empty.Version != CurrentCredentialVersion { |
| 1166 | t.Fatalf("empty file version = %d", empty.Version) |
| 1167 | } |
| 1168 | emptyRecords, err := store.Records() |
| 1169 | if err != nil { |
| 1170 | t.Fatalf("Records empty file returned error: %v", err) |
| 1171 | } |
| 1172 | if len(emptyRecords) != 0 { |
| 1173 | t.Fatalf("empty records = %#v, want none", emptyRecords) |
| 1174 | } |
| 1175 | |
| 1176 | recordB := CredentialRecord{AppID: "app_a", GitHTTPURL: "https://example.com/git/a.git", Profile: "default", ProfileAppID: "cli", UserOpenID: "ou", Status: StatusConfirmed} |
| 1177 | recordC := CredentialRecord{AppID: "app_a", GitHTTPURL: "https://example.com/git/c.git", Profile: "default", ProfileAppID: "cli", UserOpenID: "ou", Status: StatusConfirmed} |
| 1178 | if err := store.Upsert(recordB); err != nil { |
| 1179 | t.Fatalf("Upsert B returned error: %v", err) |
| 1180 | } |
| 1181 | if err := store.Upsert(recordC); err != nil { |
| 1182 | t.Fatalf("Upsert C returned error: %v", err) |
| 1183 | } |
| 1184 | records, err := store.Records() |
| 1185 | if err != nil { |
| 1186 | t.Fatalf("Records returned error: %v", err) |
| 1187 | } |
| 1188 | if len(records) != 1 || records[0].GitHTTPURL != recordC.GitHTTPURL { |
| 1189 | t.Fatalf("records = %#v, want latest app-scoped record", records) |
| 1190 | } |
| 1191 | matches, err := store.FindByAppID("app_a", ProfileContext{Profile: "default", ProfileAppID: "cli", UserOpenID: "ou"}) |
nothing calls this directly
no test coverage detected