Files
postmarketos-mkinitfs/main_test.go
Clayton Craft 155a7bc17f stripExts: don't use a cutset when removing extension
I misread what strings.Trim does, the 2nd param is a _cut set_, so this
was removing any occurance any characters in the 2nd param. Since the
file extension is always a suffix, this uses TrimSuffix.

Fixes a bug where 'virtio_blk.ko' was being trimmed to 'virtio_bl'
2021-09-01 11:03:38 -07:00

27 lines
572 B
Go

// Copyright 2021 Clayton Craft <clayton@craftyguy.net>
// SPDX-License-Identifier: GPL-3.0-or-later
package main
import (
"testing"
)
func TestStripExts(t *testing.T) {
tables := []struct {
in string
expected string
}{
{"/foo/bar/bazz.tar", "/foo/bar/bazz"},
{"file.tar.gz.xz.zip", "file"},
{"another_file", "another_file"},
{"a.b.c.d.e.f.g.h.i", "a"},
{"virtio_blk.ko", "virtio_blk"},
}
for _, table := range tables {
out := stripExts(table.in)
if out != table.expected {
t.Errorf("Expected: %q, got: %q", table.expected, out)
}
}
}