package bambunfc import ( "errors" "os" "slices" "testing" ) func TestMergeFixtures(t *testing.T) { t.Parallel() f, err := os.Open("testdata/dumps.zip") if err != nil { t.Fatal(err) } defer f.Close() tags, err := ParseZip(f) if err != nil { t.Fatal(err) } spools, err := Merge(tags) if err != nil { t.Fatal(err) } if len(spools) != 3 { t.Fatalf("len(spools) = %d; want 3", len(spools)) } byTray := map[string]Spool{} for _, s := range spools { byTray[s.TrayUID] = s } a, ok := byTray["2fb8e0e972084e74bf737393b28e7b12"] if !ok { t.Fatal("missing spool A") } if !slices.Equal(a.ChipUIDs, []string{"52d60177", "e27be276"}) { t.Errorf("spool A chips %v", a.ChipUIDs) } if a.Type != "PETG Translucent" || a.Brand != BrandBambuLab { t.Errorf("spool A type/brand %s %s", a.Type, a.Brand) } b, ok := byTray["aa42f322172c48e99c0ece895346ea9f"] if !ok { t.Fatal("missing spool B") } if !slices.Equal(b.ChipUIDs, []string{"92a80577", "b2d32177"}) { t.Errorf("spool B chips %v", b.ChipUIDs) } c, ok := byTray["3cb568b7af4f41819412fe60afc5c446"] if !ok { t.Fatal("missing spool C") } if !slices.Equal(c.ChipUIDs, []string{"92b6fb31", "f28c58ed"}) { t.Errorf("spool C chips %v", c.ChipUIDs) } if c.Type != "PETG Basic" || c.Color.Hex() != "#000000FF" { t.Errorf("spool C %s %s", c.Type, c.Color.Hex()) } for i := 1; i < len(spools); i++ { if spools[i-1].TrayUID > spools[i].TrayUID { t.Fatalf("spools not sorted by TrayUID") } } } func TestMergeConflict(t *testing.T) { t.Parallel() a := Tag{Brand: BrandBambuLab, TrayUID: "aa", ChipUID: "01", Type: "PLA", Material: "PLA", WeightG: 1000} b := Tag{Brand: BrandBambuLab, TrayUID: "aa", ChipUID: "02", Type: "PETG", Material: "PETG", WeightG: 1000} _, err := Merge([]Tag{a, b}) if !errors.Is(err, ErrConflict) { t.Errorf("err = %v; want ErrConflict", err) } } func TestMergeEmptyTray(t *testing.T) { t.Parallel() _, err := Merge([]Tag{{Brand: BrandBambuLab, ChipUID: "01", Type: "PLA"}}) if !errors.Is(err, ErrIncomplete) { t.Errorf("err = %v; want ErrIncomplete", err) } }