api-swift / Tests / IrdAPITests / EnumTests.swift
122 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Foundation
import Testing
@testable import IrdAPI

@Suite struct EnumTests {
    @Test func unknownValuesRoundTripAsUnrecognized() throws {
        let decoded = try JSONDecoder().decode([InstanceState].self, from: Data(#"["running","hibernating"]"#.utf8))
        #expect(decoded == [.running, .unrecognized("hibernating")])
        #expect(decoded[1].rawValue == "hibernating")
        let encoded = String(decoding: try JSONEncoder().encode(decoded), as: UTF8.self)
        #expect(encoded == #"["running","hibernating"]"#)
    }

    @Test func knownListsEverySpecValue() {
        #expect(InstanceState.known.contains(.running))
        #expect(!InstanceState.known.isEmpty)
        #expect(JobStatus.known == [.queued, .processing, .succeeded, .failed])
        #expect(UploadFormat(rawValue: "car") == .car)
        #expect(MetricSeriesUnit.bytesPerSecond.rawValue == "bytes/s")
    }

    @Test func jobSpecCarriesTheDiscriminator() throws {
        let spec = JobSpec.embedding(EmbeddingJob(input: "hello"))
        let json = try JSONValue(encoding: spec)
        #expect(json["type"] == "embedding")
        #expect(json["input"] == "hello")
        #expect(try JSONDecoder().decode(JobSpec.self, from: try json.serialized()) == spec)
        #expect(spec.type == "embedding")
    }

    @Test func metricPointsAreArrays() throws {
        let series = try JSONDecoder().decode(MetricSeries.self, from: Data(#"{"name":"cpu","unit":"percent","points":[[1700000000,12.5]]}"#.utf8))
        #expect(series.points == [MetricPoint(timestamp: 1_700_000_000, value: 12.5)])
        #expect(String(decoding: try JSONEncoder().encode(series.points), as: UTF8.self) == "[[1700000000,12.5]]")
    }
}

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/api-swift.git