@@ -2,6 +2,7 @@ package installvalidation_test
22
33import (
44 "errors"
5+ "os"
56 "strings"
67 "testing"
78
@@ -64,3 +65,118 @@ func TestLocalPathFailureReason_Missing(t *testing.T) {
6465 t .Fatal ("expected a failure reason for missing path" )
6566 }
6667}
68+
69+ func TestLocalPathNoMarkersHint_EmptyDir (t * testing.T ) {
70+ dir := t .TempDir ()
71+ hint := installvalidation .LocalPathNoMarkersHint (dir )
72+ if hint != "" {
73+ t .Errorf ("expected empty hint for empty dir, got %q" , hint )
74+ }
75+ }
76+
77+ func TestLocalPathNoMarkersHint_WithSubpackage (t * testing.T ) {
78+ dir := t .TempDir ()
79+ sub := dir + "/mypkg"
80+ if err := os .MkdirAll (sub , 0o755 ); err != nil {
81+ t .Fatal (err )
82+ }
83+ if err := os .WriteFile (sub + "/apm.yml" , []byte ("name: mypkg\n " ), 0o644 ); err != nil {
84+ t .Fatal (err )
85+ }
86+ hint := installvalidation .LocalPathNoMarkersHint (dir )
87+ if hint == "" {
88+ t .Error ("expected a hint for dir with sub-package" )
89+ }
90+ }
91+
92+ func TestLocalPathFailureReason_ValidPath (t * testing.T ) {
93+ dir := t .TempDir ()
94+ if err := os .WriteFile (dir + "/apm.yml" , []byte ("name: test\n " ), 0o644 ); err != nil {
95+ t .Fatal (err )
96+ }
97+ reason := installvalidation .LocalPathFailureReason (dir )
98+ if reason != "" {
99+ t .Errorf ("expected empty reason for valid path, got %q" , reason )
100+ }
101+ }
102+
103+ func TestLocalPathFailureReason_NoMarkers (t * testing.T ) {
104+ dir := t .TempDir ()
105+ reason := installvalidation .LocalPathFailureReason (dir )
106+ if reason == "" {
107+ t .Error ("expected failure reason for path with no markers" )
108+ }
109+ }
110+
111+ func TestNewPackageProber_Fields (t * testing.T ) {
112+ p := installvalidation .NewPackageProber ("github.com" , "mytoken" )
113+ if p == nil {
114+ t .Fatal ("NewPackageProber returned nil" )
115+ }
116+ if p .Host != "github.com" {
117+ t .Errorf ("expected Host=github.com, got %q" , p .Host )
118+ }
119+ if p .AuthToken != "mytoken" {
120+ t .Errorf ("expected AuthToken=mytoken" )
121+ }
122+ if p .Timeout == 0 {
123+ t .Error ("expected non-zero timeout" )
124+ }
125+ }
126+
127+ func TestProbeResult_Fields (t * testing.T ) {
128+ r := installvalidation.ProbeResult {Reachable : true }
129+ if ! r .Reachable {
130+ t .Error ("Reachable should be true" )
131+ }
132+ r2 := installvalidation.ProbeResult {Reachable : false , Reason : "not found" , IsAuthError : true }
133+ if r2 .Reachable || ! r2 .IsAuthError {
134+ t .Error ("unexpected ProbeResult fields" )
135+ }
136+ r3 := installvalidation.ProbeResult {IsTLSError : true , Reason : "tls failed" }
137+ if ! r3 .IsTLSError {
138+ t .Error ("IsTLSError should be true" )
139+ }
140+ }
141+
142+ func TestIsADOAuthFailureSignal_Unauthorized (t * testing.T ) {
143+ if ! installvalidation .IsADOAuthFailureSignal (401 , "" ) {
144+ t .Error ("401 should be ADO auth failure" )
145+ }
146+ if ! installvalidation .IsADOAuthFailureSignal (403 , "" ) {
147+ t .Error ("403 should be ADO auth failure" )
148+ }
149+ }
150+
151+ func TestIsADOAuthFailureSignal_BodyMatch (t * testing.T ) {
152+ if ! installvalidation .IsADOAuthFailureSignal (200 , "TFS Auth failed" ) {
153+ t .Error ("TFS Auth body should be ADO auth failure" )
154+ }
155+ if ! installvalidation .IsADOAuthFailureSignal (200 , "unauthorized" ) {
156+ t .Error ("unauthorized body should be ADO auth failure" )
157+ }
158+ }
159+
160+ func TestIsADOAuthFailureSignal_False (t * testing.T ) {
161+ if installvalidation .IsADOAuthFailureSignal (200 , "ok response" ) {
162+ t .Error ("200 with ok body should not be ADO auth failure" )
163+ }
164+ }
165+
166+ func TestValidatePackageExists_LocalPath (t * testing.T ) {
167+ dir := t .TempDir ()
168+ if err := os .WriteFile (dir + "/apm.yml" , []byte ("name: test\n " ), 0o644 ); err != nil {
169+ t .Fatal (err )
170+ }
171+ result := installvalidation .ValidatePackageExists (dir , "github.com" , "" , false )
172+ if ! result .Reachable {
173+ t .Errorf ("expected Reachable=true for local path with apm.yml, got: %q" , result .Reason )
174+ }
175+ }
176+
177+ func TestValidatePackageExists_InvalidSpec (t * testing.T ) {
178+ result := installvalidation .ValidatePackageExists ("notapath" , "github.com" , "" , false )
179+ if result .Reachable {
180+ t .Error ("expected Reachable=false for invalid spec" )
181+ }
182+ }
0 commit comments