Paillasse/correcteur/lab_test.go

56 lines
1.6 KiB
Go
Raw Normal View History

package main
import "testing"
func TestLab08(t *testing.T) {
l, err := chargerLab("../labs", "08-deux-lan-routeur")
if err != nil {
t.Fatal(err)
}
v, ok := l.verification("forwarding")
if !ok || v.Machine != "routeur" || v.Attendu.CodeRetour != 0 || v.Commande == "" {
t.Fatalf("vérification forwarding mal lue : %+v", v)
}
if _, ok := l.verification("inexistante"); ok {
t.Fatal("une vérification inconnue ne doit pas être trouvée")
}
}
func TestMachineDuNom(t *testing.T) {
l := &lab{}
for _, n := range []string{"a", "pc-a", "routeur"} {
l.Machines = append(l.Machines, struct {
Nom string `yaml:"nom"`
}{n})
}
cas := map[string]string{
"lab-session-3-e1-pc-a": "pc-a",
"stock-08-deux-lan-routeur-x-e2-a": "a",
"lab-session-3-e1-routeur": "routeur",
"vm-sans-rapport": "",
}
for nom, attendu := range cas {
if got := l.machineDuNom(nom); got != attendu {
t.Errorf("machineDuNom(%q) = %q, attendu %q", nom, got, attendu)
}
}
}
func TestAttendu(t *testing.T) {
a := attendu{CodeRetour: 0, SortieContient: "ok"}
if !a.satisfait(0, "tout est ok") || a.satisfait(1, "ok") || a.satisfait(0, "non") {
t.Fatal("règle code_retour + sortie_contient mal appliquée")
}
}
func TestValidationIdentifiants(t *testing.T) {
for _, mauvais := range []string{"../etc", "08/../..", "A", "", "lab;rm"} {
if reIdent.MatchString(mauvais) {
t.Errorf("%q ne doit pas être accepté", mauvais)
}
}
if reInstance.MatchString("not-a-uuid") || !reInstance.MatchString("8c8d5447-80fe-40da-ae65-812e077941f8") {
t.Fatal("validation d'uuid incorrecte")
}
}