|
| 1 | +package cmd |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestParseImportURLSpecifier_PreservesPortAndPathWithMainArtifactSuffix(t *testing.T) { |
| 6 | + in := "http://localhost:8080/spec.yaml:true" |
| 7 | + url, main, secret := parseImportURLSpecifier(in) |
| 8 | + |
| 9 | + if url != "http://localhost:8080/spec.yaml" { |
| 10 | + t.Fatalf("url mismatch: got %q", url) |
| 11 | + } |
| 12 | + if main != true { |
| 13 | + t.Fatalf("mainArtifact mismatch: got %v", main) |
| 14 | + } |
| 15 | + if secret != "" { |
| 16 | + t.Fatalf("secret mismatch: got %q", secret) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +func TestParseImportURLSpecifier_PreservesQueryAndFragment(t *testing.T) { |
| 21 | + in := "https://example.com:8443/spec.yaml?x=1#frag:false" |
| 22 | + url, main, secret := parseImportURLSpecifier(in) |
| 23 | + |
| 24 | + if url != "https://example.com:8443/spec.yaml?x=1#frag" { |
| 25 | + t.Fatalf("url mismatch: got %q", url) |
| 26 | + } |
| 27 | + if main != false { |
| 28 | + t.Fatalf("mainArtifact mismatch: got %v", main) |
| 29 | + } |
| 30 | + if secret != "" { |
| 31 | + t.Fatalf("secret mismatch: got %q", secret) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func TestParseImportURLSpecifier_WithSecretSuffix(t *testing.T) { |
| 36 | + in := "http://localhost:8080/spec.yaml:true:mySecret" |
| 37 | + url, main, secret := parseImportURLSpecifier(in) |
| 38 | + |
| 39 | + if url != "http://localhost:8080/spec.yaml" { |
| 40 | + t.Fatalf("url mismatch: got %q", url) |
| 41 | + } |
| 42 | + if main != true { |
| 43 | + t.Fatalf("mainArtifact mismatch: got %v", main) |
| 44 | + } |
| 45 | + if secret != "mySecret" { |
| 46 | + t.Fatalf("secret mismatch: got %q", secret) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func TestParseImportURLSpecifier_NoSuffixes_Unchanged(t *testing.T) { |
| 51 | + in := "http://localhost:8080/spec.yaml" |
| 52 | + url, main, secret := parseImportURLSpecifier(in) |
| 53 | + |
| 54 | + if url != in { |
| 55 | + t.Fatalf("url mismatch: got %q", url) |
| 56 | + } |
| 57 | + if main != true { |
| 58 | + t.Fatalf("mainArtifact mismatch: got %v", main) |
| 59 | + } |
| 60 | + if secret != "" { |
| 61 | + t.Fatalf("secret mismatch: got %q", secret) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +func TestParseImportURLSpecifier_PortOnly_NoSuffixes_Unchanged(t *testing.T) { |
| 66 | + in := "http://localhost:8080/spec.yaml:1234" |
| 67 | + url, main, secret := parseImportURLSpecifier(in) |
| 68 | + |
| 69 | + if url != in { |
| 70 | + t.Fatalf("url mismatch: got %q", url) |
| 71 | + } |
| 72 | + if main != true { |
| 73 | + t.Fatalf("mainArtifact mismatch: got %v", main) |
| 74 | + } |
| 75 | + if secret != "" { |
| 76 | + t.Fatalf("secret mismatch: got %q", secret) |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +func TestParseImportFileSpecifier_SuffixBool(t *testing.T) { |
| 81 | + in := "./specs/openapi.yaml:false" |
| 82 | + path, main := parseImportFileSpecifier(in) |
| 83 | + if path != "./specs/openapi.yaml" { |
| 84 | + t.Fatalf("path mismatch: got %q", path) |
| 85 | + } |
| 86 | + if main != false { |
| 87 | + t.Fatalf("mainArtifact mismatch: got %v", main) |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +func TestParseImportFileSpecifier_NoSuffix_Unchanged(t *testing.T) { |
| 92 | + in := "./specs/openapi.yaml" |
| 93 | + path, main := parseImportFileSpecifier(in) |
| 94 | + if path != in { |
| 95 | + t.Fatalf("path mismatch: got %q", path) |
| 96 | + } |
| 97 | + if main != true { |
| 98 | + t.Fatalf("mainArtifact mismatch: got %v", main) |
| 99 | + } |
| 100 | +} |
| 101 | + |
0 commit comments