2024-04-29 17:42:37 +00:00
package utils_test
import (
2024-06-23 08:24:36 +00:00
. "github.com/mudler/LocalAI/pkg/utils"
2024-04-29 17:42:37 +00:00
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe ( "utils/base64 tests" , func ( ) {
2024-06-24 06:34:36 +00:00
It ( "GetImageURLAsBase64 can strip jpeg data url prefixes" , func ( ) {
2024-04-29 17:42:37 +00:00
// This one doesn't actually _care_ that it's base64, so feed "bad" data in this test in order to catch a change in that behavior for informational purposes.
input := "data:image/jpeg;base64,FOO"
2024-09-19 09:21:59 +00:00
b64 , err := GetContentURIAsBase64 ( input )
2024-04-29 17:42:37 +00:00
Expect ( err ) . To ( BeNil ( ) )
Expect ( b64 ) . To ( Equal ( "FOO" ) )
} )
2024-06-24 06:34:36 +00:00
It ( "GetImageURLAsBase64 can strip png data url prefixes" , func ( ) {
// This one doesn't actually _care_ that it's base64, so feed "bad" data in this test in order to catch a change in that behavior for informational purposes.
input := "data:image/png;base64,BAR"
2024-09-19 09:21:59 +00:00
b64 , err := GetContentURIAsBase64 ( input )
2024-06-24 06:34:36 +00:00
Expect ( err ) . To ( BeNil ( ) )
Expect ( b64 ) . To ( Equal ( "BAR" ) )
} )
2024-04-29 17:42:37 +00:00
It ( "GetImageURLAsBase64 returns an error for bogus data" , func ( ) {
input := "FOO"
2024-09-19 09:21:59 +00:00
b64 , err := GetContentURIAsBase64 ( input )
2024-04-29 17:42:37 +00:00
Expect ( b64 ) . To ( Equal ( "" ) )
Expect ( err ) . ToNot ( BeNil ( ) )
Expect ( err ) . To ( MatchError ( "not valid string" ) )
} )
It ( "GetImageURLAsBase64 can actually download images and calculates something" , func ( ) {
// This test doesn't actually _check_ the results at this time, which is bad, but there wasn't a test at all before...
input := "https://upload.wikimedia.org/wikipedia/en/2/29/Wargames.jpg"
2024-09-19 09:21:59 +00:00
b64 , err := GetContentURIAsBase64 ( input )
2024-04-29 17:42:37 +00:00
Expect ( err ) . To ( BeNil ( ) )
Expect ( b64 ) . ToNot ( BeNil ( ) )
} )
} )