// Copyright (c) 2022 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//

//
// WARNING: This file is auto-generated - DO NOT EDIT!
//

use clap::crate_version;

const KATA_CTL_VERSION: &str = "@KATA_CTL_VERSION@";

pub fn get() -> Result<String, String> {
    if KATA_CTL_VERSION.trim().is_empty() {
        Err("Unable to retrieve kata Version. Check that Kata is properly installed".to_string())
    } else {
        let version = format!("{}-{}", KATA_CTL_VERSION, crate_version!());

        Ok(version)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use semver::Version;

    #[test]
    fn test_get() {
        let version = get().unwrap();
        let v = Version::parse(&version).unwrap();

        assert!(!v.major.to_string().is_empty());
        assert!(!v.minor.to_string().is_empty());
        assert!(!v.patch.to_string().is_empty());
        assert!(!v.pre.to_string().is_empty());
    }
}
