Skip to content

Commit 2101c4a

Browse files
author
daniel.iwaniec
committed
Update tests for start.go
1 parent a032b91 commit 2101c4a

File tree

1 file changed

+0
-74
lines changed

1 file changed

+0
-74
lines changed

cmd/minikube/cmd/start_test.go

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
cfg "k8s.io/minikube/pkg/minikube/config"
3131
"k8s.io/minikube/pkg/minikube/constants"
3232
"k8s.io/minikube/pkg/minikube/cruntime"
33-
"k8s.io/minikube/pkg/minikube/detect"
3433
"k8s.io/minikube/pkg/minikube/driver"
3534
"k8s.io/minikube/pkg/minikube/proxy"
3635
)
@@ -581,171 +580,98 @@ func TestIsTwoDigitSemver(t *testing.T) {
581580
}
582581

583582
func TestValidatePorts(t *testing.T) {
584-
isMicrosoftWSL := detect.IsMicrosoftWSL()
585583
type portTest struct {
586-
// isTarget indicates whether or not the test case is covered
587-
// because validatePorts behaves differently depending on whether process is running in WSL in windows or not.
588-
isTarget bool
589584
ports []string
590585
errorMsg string
591586
}
592587
var tests = []portTest{
593588
{
594-
isTarget: true,
595589
ports: []string{"8080:80"},
596590
errorMsg: "",
597591
},
598592
{
599-
isTarget: true,
600593
ports: []string{"8080:80/tcp", "8080:80/udp"},
601594
errorMsg: "",
602595
},
603596
{
604-
isTarget: true,
605597
ports: []string{"test:8080"},
606598
errorMsg: "Sorry, one of the ports provided with --ports flag is not valid [test:8080] (Invalid hostPort: test)",
607599
},
608600
{
609-
isTarget: true,
610601
ports: []string{"0:80"},
611602
errorMsg: "Sorry, one of the ports provided with --ports flag is outside range: 0",
612603
},
613604
{
614-
isTarget: true,
615605
ports: []string{"0:80/tcp"},
616606
errorMsg: "Sorry, one of the ports provided with --ports flag is outside range: 0",
617607
},
618608
{
619-
isTarget: true,
620609
ports: []string{"65536:80/udp"},
621610
errorMsg: "Sorry, one of the ports provided with --ports flag is not valid [65536:80/udp] (Invalid hostPort: 65536)",
622611
},
623612
{
624-
isTarget: true,
625613
ports: []string{"0-1:80-81/tcp"},
626614
errorMsg: "Sorry, one of the ports provided with --ports flag is outside range: 0",
627615
},
628616
{
629-
isTarget: true,
630617
ports: []string{"0-1:80-81/udp"},
631618
errorMsg: "Sorry, one of the ports provided with --ports flag is outside range: 0",
632619
},
633620
{
634-
isTarget: !isMicrosoftWSL,
635621
ports: []string{"80:80", "1023-1025:8023-8025", "1023-1025:8023-8025/tcp", "1023-1025:8023-8025/udp"},
636622
errorMsg: "",
637623
},
638624
{
639-
isTarget: isMicrosoftWSL,
640-
ports: []string{"80:80"},
641-
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024): 80",
642-
},
643-
{
644-
isTarget: isMicrosoftWSL,
645-
ports: []string{"1023-1025:8023-8025"},
646-
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024): 1023",
647-
},
648-
{
649-
isTarget: isMicrosoftWSL,
650-
ports: []string{"1023-1025:8023-8025/tcp"},
651-
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024): 1023",
652-
},
653-
{
654-
isTarget: isMicrosoftWSL,
655-
ports: []string{"1023-1025:8023-8025/udp"},
656-
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024): 1023",
657-
},
658-
{
659-
isTarget: true,
660625
ports: []string{"127.0.0.1:8080:80", "127.0.0.1:8081:80/tcp", "127.0.0.1:8081:80/udp", "127.0.0.1:8082-8083:8082-8083/tcp"},
661626
errorMsg: "",
662627
},
663628
{
664-
isTarget: true,
665629
ports: []string{"1000.0.0.1:80:80"},
666630
errorMsg: "Sorry, one of the ports provided with --ports flag is not valid [1000.0.0.1:80:80] (Invalid ip address: 1000.0.0.1)",
667631
},
668632
{
669-
isTarget: !isMicrosoftWSL,
670633
ports: []string{"127.0.0.1:80:80", "127.0.0.1:81:81/tcp", "127.0.0.1:81:81/udp", "127.0.0.1:82-83:82-83/tcp", "127.0.0.1:82-83:82-83/udp"},
671634
errorMsg: "",
672635
},
673636
{
674-
isTarget: isMicrosoftWSL,
675-
ports: []string{"127.0.0.1:80:80"},
676-
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024): 80",
677-
},
678-
{
679-
isTarget: isMicrosoftWSL,
680-
ports: []string{"127.0.0.1:81:81/tcp"},
681-
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024): 81",
682-
},
683-
{
684-
isTarget: isMicrosoftWSL,
685-
ports: []string{"127.0.0.1:81:81/udp"},
686-
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024): 81",
687-
},
688-
{
689-
isTarget: isMicrosoftWSL,
690-
ports: []string{"127.0.0.1:80-83:80-83/tcp"},
691-
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024): 80",
692-
},
693-
{
694-
isTarget: isMicrosoftWSL,
695-
ports: []string{"127.0.0.1:80-83:80-83/udp"},
696-
errorMsg: "Sorry, you cannot use privileged ports on the host (below 1024): 80",
697-
},
698-
{
699-
isTarget: true,
700637
ports: []string{"80"},
701638
errorMsg: "",
702639
},
703640
{
704-
isTarget: true,
705641
ports: []string{"80", "65535", "65536"},
706642
errorMsg: "Sorry, one of the ports provided with --ports flag is outside range: 65536",
707643
},
708644
{
709-
isTarget: true,
710645
ports: []string{"0", "80", "65535"},
711646
errorMsg: "Sorry, one of the ports provided with --ports flag is outside range: 0",
712647
},
713648
{
714-
isTarget: true,
715649
ports: []string{"cats"},
716650
errorMsg: "Sorry, one of the ports provided with --ports flag is not valid: cats",
717651
},
718652
{
719-
isTarget: true,
720653
ports: []string{"127.0.0.1:81:0/tcp"},
721654
errorMsg: "Sorry, one of the ports provided with --ports flag is outside range: 0",
722655
},
723656
{
724-
isTarget: true,
725657
ports: []string{"127.0.0.1:81:65536/tcp"},
726658
errorMsg: "Sorry, one of the ports provided with --ports flag is not valid [127.0.0.1:81:65536/tcp] (Invalid containerPort: 65536)",
727659
},
728660
{
729-
isTarget: true,
730661
ports: []string{"1-65536:80-81/tcp"},
731662
errorMsg: "Sorry, one of the ports provided with --ports flag is not valid [1-65536:80-81/tcp] (Invalid hostPort: 1-65536)",
732663
},
733664
{
734-
isTarget: true,
735665
ports: []string{"1-80:0-81/tcp"},
736666
errorMsg: "Sorry, one of the ports provided with --ports flag is not valid [1-80:0-81/tcp] (Invalid ranges specified for container and host Ports: 0-81 and 1-80)",
737667
},
738668
{
739-
isTarget: true,
740669
ports: []string{"1-80:1-65536/tcp"},
741670
errorMsg: "Sorry, one of the ports provided with --ports flag is not valid [1-80:1-65536/tcp] (Invalid containerPort: 1-65536)",
742671
},
743672
}
744673
for _, test := range tests {
745674
t.Run(strings.Join(test.ports, ","), func(t *testing.T) {
746-
if !test.isTarget {
747-
return
748-
}
749675
gotError := ""
750676
got := validatePorts(test.ports)
751677
if got != nil {

0 commit comments

Comments
 (0)